<template>
  <el-dialog
    class="gl_dialog_TitleLine gl_dl_footer"
    width="440px"
    title="审核"
    :visible.sync="approveDialogVisible"
    :close-on-click-modal="false"
    :close-on-press-escape="false"
  >
    <el-form ref="approveVO" :model="approveVO" label-position="top" size="mini" @submit.native.prevent>
      <el-form-item
        label="审核状态"
        prop="approveStatusCode"
        :rules="[
          { required: true, message: '审核状态不能为空'}
        ]"
      >
        <el-select v-model="approveVO.approveStatusCode" placeholder="请选择审核状态" style="width: 100%;" @change="changeSelect">
          <el-option v-for="item in dict.trainningApproveProcessResult" :key="item.code" :value="item.code" :label="item.value" />
        </el-select>
      </el-form-item>
      <el-form-item
        v-if="approveVO.approveStatusCode === 'ApproveFailed'"
        label="原因"
        prop="approveRemark"
        :rules="[
          { required: true, message: '原因不能为空'}
        ]"
      >
        <el-input
          v-model="approveVO.approveRemark"
          type="textarea"
          :autosize="{ minRows: 2, maxRows: 4}"
          placeholder="请填写未通过原因"
        />
      </el-form-item>
      <el-form-item v-if="approveVO.approveStatusCode === 'ApproveSuccess'" label="优化建议">
        <el-input
          v-model="approveVO.approveRemark"
          type="textarea"
          :autosize="{ minRows: 2, maxRows: 4}"
          placeholder="请填写优化意见与建议"
        />
      </el-form-item>
    </el-form>
    <div slot="footer">
      <el-button size="mini" @click="close()">取 消</el-button>
      <el-button size="mini" type="primary" @click="updateGameApproveStatus()">确 定</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { mapState, mapActions } from 'vuex';
import { SiSTKWTrainEntryApproveInput } from '@/lib/form/train/swaggerForm';
import {
  api_POST_TrainTrainningEntryApprovalSetEntryApproval
} from '@/extend/api/trainswaggerApi/app';
export default {
  data() {
    return {
      approveDialogVisible: false,
      approveVO: new SiSTKWTrainEntryApproveInput()
    };
  },
  computed: {
    ...mapState({
      dict: state => state.dict.dict
    })
  },
  created() {
    this.getDict();
  },
  methods: {
    ...mapActions({ getDict: 'dict/getDict' }),
    open(id) {
      this.approveDialogVisible = true;
      this.approveVO.id = id;
    },
    close() {
      this.approveDialogVisible = false;
      this.$refs['approveVO'].resetFields();
    },
    changeSelect(val) {
      if (val === 'ApproveSuccess') {
        this.$refs['approveVO'].clearValidate('approveRemark');
      }
    },
    updateGameApproveStatus() {
      var that = this;
      that.$refs['approveVO'].validate(valid => {
        if (valid) {
          api_POST_TrainTrainningEntryApprovalSetEntryApproval(this.approveVO).then(res => {
            that.$message({ type: 'success', message: '操作成功！' });
            that.close();
          }, error => {
            that.$message({ type: 'error', message: '操作失败！' + (error.error && error.error.message || '') });
          });
        }
      });
    }
  }
};
</script>

<style>

</style>
